package com.xii.oss.Controller;

import com.xii.commonutils.R;
import com.xii.oss.Service.IOssService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/eduoss/fileoss")
//@CrossOrigin   //跨域
public class OssController {
    @Autowired
    private IOssService ossService;
    /**
     * 文件上传
     *
     * @param file
     */
    @ApiOperation(value = "文件上传")
    @PostMapping("upload")
    public R upload(
            @ApiParam(name = "file", value = "文件", required = true)
            @RequestParam("file") MultipartFile file) {            //MultipartFile  得到上传的文件  这就是传过来的文件的对象
        String uploadUrl = ossService.uploadFile(file);          //  返回上传后文件在oss中的路径 用于数据库中存储
        //返回r对象
        return R.ok().message("文件上传成功").data("url", uploadUrl);
    }
}
